package com.demo.cms.action.manage;

import java.util.ArrayList;
import java.util.List;

import com.demo.cms.model.Article;
import com.demo.core.dao.base.support.ResultSearchResult;
import com.demo.core.dao.base.support.SearchArgumentSupport;
import com.demo.core.model.Feedback;
import com.demo.core.model.Site;
import com.demo.core.service.base.FeedbackService;
import com.demo.security.annotation.function.Function;
import com.demo.webapp.action.PageAction;
/**
 * 反馈管理Action
 * 
 * @author ryuu.kk
 */
@Function(id = 105000, pid = 10, code = "manage.feedback")
public class FeedbackAction extends PageAction {

	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = 3987575580155587826L;

	/**
	 * 留言主键ID
	 */
	private Long id;
	
	/**
	 * 留言类型
	 */
	private String type;
	
	/**
	 * 留言展示模式 0:列表展示;1:树形展示等
	 */
	private int mode = 0;
	
	/**
	 * 文章模型
	 */
	private Article article;
	
	/**
	 * 留言模型
	 */
	private Feedback feedback;
	
	/**
	 * 留言列表
	 */
	private List<Feedback> feedbackList;

	/**
	 * 留言服务
	 */
	private FeedbackService feedbackService;
	
	/**
	 * 留言列表
	 * @return String
	 */
	@Function(id = 105010, pid = 105000, code = "manage.feedback.list")
	public String list() {
		
		Site site = getSite();
		Long siteId = site.getId();
		
		SearchArgumentSupport args = getArgumentSupport();
		
		ResultSearchResult<Feedback>  resultSupport = null;
		
		if (mode < 1) {
			resultSupport = feedbackService.search(siteId, type, args);
		} else {
			// 树形结构
			resultSupport = feedbackService.search(siteId, type, args);
		}
		this.setResultSupport(resultSupport);
		this.feedbackList = new ArrayList<Feedback>(resultSupport.getResults());
		
		return SUCCESS;
	}
	
	/**
	 * 创建留言
	 * @return String
	 */
	@Function(id = 105020, pid = 105000, code = "manage.feedback.create")
	public String create() {
		//feedbackService.save(this.feedback);
		return SUCCESS;
	}
	
	/**
	 * 创建留言
	 * @return String
	 */
	@Function(id = 105030, pid = 105000, code = "manage.feedback.save")
	public String save() {
		feedbackService.save(this.feedback);
		addActionMessage("反馈保存成功");
		return CALLBACK;
	}
	
	/**
	 * 留言修改
	 * @return String
	 */
	@Function(id = 105040, pid = 105000, code = "manage.feedback.edit")
	public String edit() {
		
		this.feedback = feedbackService.find(id);
		return SUCCESS;
	}
	
	/**
	 * 留言状态更新(审核)
	 * @return String
	 */
	@Function(id = 105050, pid = 105000, code = "manage.feedback.update")
	public String update() {
		
		feedbackService.update(id, feedback);
		addActionMessage("反馈更新成功");
		return CALLBACK;
	}
	
	/**
	 * 删除留言
	 * @return String
	 */
	@Function(id = 105060, pid = 105000, code = "manage.feedback.delete")
	public String delete() {
		feedbackService.delete(id);
		addActionMessage("反馈删除成功");
		return CALLBACK;
	}
	
	/**
	 * 更新审核阶段
	 * @return String
	 */
	@Function(id = 105070, pid = 105000, code = "manage.feedback.setp")
	public String setp() {
		//feedbackService.update(id, checkStep, isChecked)
		return CALLBACK;
	}
	
	// ~ settings here ========================================================================
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public int getMode() {
		return mode;
	}

	public void setMode(int mode) {
		this.mode = mode;
	}

	public Article getArticle() {
		return article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}

	public Feedback getFeedback() {
		return feedback;
	}

	public List<Feedback> getFeedbackList() {
		return feedbackList;
	}

	public void setFeedback(Feedback feedback) {
		this.feedback = feedback;
	}

	public void setFeedbackService(FeedbackService feedbackService) {
		this.feedbackService = feedbackService;
	}
}
